/*
 * @Author: wuzhen
 * @Date: 2020-01-13 13:28:41
 * @LastEditors  : wuzhen
 * @LastEditTime : 2020-01-20 10:29:05
 * @Description: main.js
 */
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
// 自定义全局指令
import directive from "@/directive";
// 自定义全局组件
import components from "@/components";
// 扩展方法
import * as utils from "@/libs/units";
import "view-design/dist/styles/iview.css";
import VueI18n from "vue-i18n"; //国际化
import langOptions from "@/assets/i18n";
// 引入图片预览插件
import preview from "vue-photo-preview";
import "vue-photo-preview/dist/skin.css";
// 引入自定义滚动条插件
import GeminiScrollbar from "vue-gemini-scrollbar";
// 引入加载更多插件
import infiniteScroll from "vue-infinite-scroll";
// moment日期格式化
import moment from "moment";
// 图片预览
import Viewer from "v-viewer";
import "viewerjs/dist/viewer.css";

// IMWebSocket
import IMWebSocket from "@/libs/socket";

import Mixin from "@/mixins";

// 国际化
Vue.use(VueI18n);
const i18n = new VueI18n(langOptions);

// 注册全局组件
Vue.use(components);
// 注册全局自定义指令
Vue.use(directive);
Vue.use(preview);
Vue.use(GeminiScrollbar);
Vue.use(infiniteScroll);

Viewer.setDefaults({
  Options: {
    inline: true,
    button: true,
    navbar: false,
    title: false,
    toolbar: true,
    tooltip: true,
    movable: true,
    zoomable: true,
    rotatable: true,
    scalable: true,
    transition: true,
    fullscreen: true,
    keyboard: true,
    url: "data-source"
  }
});
Vue.use(Viewer);

// 全局配置日期格式化
Vue.prototype.$fmtMoment = (date, format) => {
  if (date) {
    return moment(date).format(format || "YYYY-MM-DD HH:mm:ss");
  }
  return null;
};

/* 扩展方法 */
for (let prop in utils) {
  Vue.prototype["$" + prop] = utils[prop];
}

// 全局配置Socket
Vue.prototype.$imWebSocket = new IMWebSocket();
// 全局通讯
Vue.prototype.$bus = new Vue();

Vue.mixin(Mixin);

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount("#app");
